<?php

namespace app\admin\controller;

use think\Controller;
use think\Request;
use think\Session;

class Admin extends Controller
{
    public function _initialize()
    {

        //判断session是否存在
        if(empty(Session::get('admin_user'))){
            //跳转到 登陆页
            $this->redirect("admin/Login/index");
        }

        // 权限过滤
        $request = Request::instance();
        $mname = $request->controller();
        $aname = $request->action();

        $nodelist = Session::get('admin_user.nodelist');

        // 给管理员admin所有权限
        if(Session::get('admin_user.username') != 'admin'){
            if(empty($nodelist[$mname]) || !in_array($aname, $nodelist[$mname])){
                $this->error("抱歉！没有操作权限！");
                exit;
            }
        }

    }
}
